<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>GuessServlet.java</title>
<meta name="Generator" content="SciTE - www.Scintilla.org" />
<style type="text/css">
.S0 {
	color: #808080;
}
.S4 {
	color: #007F7F;
}
.S5 {
	font-weight: bold;
	color: #00007F;
}
.S6 {
	color: #7F007F;
}
.S10 {
	font-weight: bold;
	color: #000000;
}
span {
	font-family: 'Courier New';
	color: #000000;
	font-size: 9pt;
}
</style>
</head>
<body bgcolor="#FFFFFF">
<span><span class="S5">package</span><span class="S0"> </span>bbsimon<span class="S10">.</span>first<span class="S10">.</span>guess<span class="S10">;</span><br />
<br />
<span class="S5">import</span><span class="S0"> </span>java<span class="S10">.</span>io<span class="S10">.*;</span><br />
<span class="S5">import</span><span class="S0"> </span>java<span class="S10">.</span>util<span class="S10">.</span>Random<span class="S10">;</span><br />
<span class="S5">import</span><span class="S0"> </span>javax<span class="S10">.</span>servlet<span class="S10">.*;</span><br />
<span class="S5">import</span><span class="S0"> </span>javax<span class="S10">.</span>servlet<span class="S10">.</span>http<span class="S10">.*;</span><br />
<br />
<span class="S5">public</span><span class="S0"> </span><span class="S5">class</span><span class="S0"> </span>GuessServlet<span class="S0"> </span><span class="S5">extends</span><span class="S0"> </span>HttpServlet<span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">public</span><span class="S0"> </span><span class="S5">void</span><span class="S0"> </span>doGet<span class="S10">(</span>HttpServletRequest<span class="S0"> </span>req<span class="S10">,</span><span class="S0"> </span>HttpServletResponse<span class="S0"> </span>res<span class="S10">)</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">throws</span><span class="S0"> </span>IOException<span class="S10">,</span><span class="S0"> </span>ServletException<span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>res<span class="S10">.</span>setContentType<span class="S10">(</span><span class="S6">"text/html"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>PrintWriter<span class="S0"> </span>out<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>res<span class="S10">.</span>getWriter<span class="S10">();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;html&gt;&lt;head&gt;&lt;title&gt;Number Guess Game&lt;/title&gt;&lt;/head&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>HttpSession<span class="S0"> </span>session<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>req<span class="S10">.</span>getSession<span class="S10">();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>String<span class="S0"> </span>s<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>req<span class="S10">.</span>getParameter<span class="S10">(</span><span class="S6">"restart"</span><span class="S10">);</span><br />
<br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>s<span class="S10">.</span>equals<span class="S10">(</span><span class="S6">"yes"</span><span class="S10">))</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>session<span class="S10">.</span>setAttribute<span class="S10">(</span><span class="S6">"left"</span><span class="S10">,</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Integer<span class="S10">(</span><span class="S4">10</span><span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>Random<span class="S0"> </span>ran<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Random<span class="S10">();</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>session<span class="S10">.</span>setAttribute<span class="S10">(</span><span class="S6">"number"</span><span class="S10">,</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Integer<span class="S10">(</span>ran<span class="S10">.</span>nextInt<span class="S10">(</span><span class="S4">100</span><span class="S10">)));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;Game Start&lt;/h1&gt;&lt;p&gt;input a number between 0-100&lt;/p&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;form method=\"GET\" action=\"guess\"&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input name=\"guess\"&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input type=\"HIDDEN\" name=\"restart\" value=\"no\" /&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input type=\"SUBMIT\" value=\"Guess it\"/&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;/form&gt;&lt;br&gt;&lt;a href=\"guess?restart=yes\"&gt;Restart&lt;/a&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;br&gt;&lt;br&gt;&lt;a href=\"./\"&gt;Back&lt;/a&gt;&lt;/body&gt;&lt;/html&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><span class="S0"> </span><span class="S5">if</span><span class="S10">(</span>s<span class="S10">.</span>equals<span class="S10">(</span><span class="S6">"no"</span><span class="S10">)){</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>Integer<span class="S0"> </span>guess<span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>Integer<span class="S0"> </span>left<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S10">(</span>Integer<span class="S10">)(</span>session<span class="S10">.</span>getAttribute<span class="S10">(</span><span class="S6">"left"</span><span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>left<span class="S0"> </span><span class="S10">==</span><span class="S0"> </span><span class="S4">0</span><span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;0 left for your game is over&lt;/h1&gt;&lt;/body&gt;&lt;html&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;a href=\"./guess?restart=yes\"&gt;Start another game&lt;/a&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">try</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>guess<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>Integer<span class="S10">.</span>parseInt<span class="S10">(</span>req<span class="S10">.</span>getParameter<span class="S10">(</span><span class="S6">"guess"</span><span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>guess<span class="S0"> </span><span class="S10">&lt;</span><span class="S0"> </span><span class="S4">0</span><span class="S0"> </span><span class="S10">||</span><span class="S0"> </span>guess<span class="S0"> </span><span class="S10">&gt;</span><span class="S0"> </span><span class="S4">100</span><span class="S10">)</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">throw</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Exception<span class="S10">(</span><span class="S6">"guess number must between 0-100"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">catch</span><span class="S10">(</span>NumberFormatException<span class="S0"> </span>e<span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;You must input a number but a string or something else&lt;/h1&gt;&lt;a href=\"guess?restart=continue"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"\"&gt;Get back to continue&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href=\"guess?restart=yes\"&gt;Restart a new game&lt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"/a&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;/body&gt;&lt;/html&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">catch</span><span class="S10">(</span>Exception<span class="S0"> </span>e<span class="S10">)</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;Guess number must between 0-100&lt;/h1&gt;&lt;a href=\"guess?"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"restart=continue\"&gt;Return to continue&lt;/a&gt;&lt;br&gt;&lt;br&gt;&lt;a href=\"guess?"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"restart=yes\"&gt;Restart a new game&lt;/a&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;/body&gt;&lt;/html&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">return</span><span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>Integer<span class="S0"> </span>number<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S10">(</span>Integer<span class="S10">)(</span>session<span class="S10">.</span>getAttribute<span class="S10">(</span><span class="S6">"number"</span><span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">if</span><span class="S10">(</span>guess<span class="S0"> </span><span class="S10">&lt;</span><span class="S0"> </span>number<span class="S10">)</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;You guess is less&lt;/h1&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><span class="S0"> </span><span class="S5">if</span><span class="S10">(</span>guess<span class="S0"> </span><span class="S10">&gt;</span><span class="S0"> </span>number<span class="S10">)</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;Your guess is greater&lt;/h1&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;You got the right number: "</span><span class="S0"> </span><span class="S10">+</span><span class="S0"> </span>number<span class="S0"> </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;/h1&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>left<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span>left<span class="S0"> </span><span class="S10">-</span><span class="S0"> </span><span class="S4">1</span><span class="S10">;</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>session<span class="S10">.</span>setAttribute<span class="S10">(</span><span class="S6">"left"</span><span class="S10">,</span><span class="S0"> </span><span class="S5">new</span><span class="S0"> </span>Integer<span class="S10">(</span>left<span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;p&gt;You have "</span><span class="S0"> </span><span class="S10">+</span><span class="S0"> </span>left<span class="S0"> </span><span class="S10">+</span><span class="S0"> </span><span class="S6">" chances left&lt;/p&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;form method=\"GET\" action=\"guess\"&gt;&lt;input name="</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"\"guess\"&gt;&lt;input type=\"SUBMIT\" name=\"restart\" value=\""</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"no\"/&gt;&lt;form&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;br&gt;&lt;a href=\"guess?restart=yes\"&gt;Restart&lt;/a&gt;&lt;/body&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;/html&gt;"</span><span class="S10">);</span><br />
<br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S5">else</span><span class="S0"> </span><span class="S5">if</span><span class="S10">(</span>s<span class="S10">.</span>equals<span class="S10">(</span><span class="S6">"continue"</span><span class="S10">))</span><span class="S0"> </span><span class="S10">{</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>Integer<span class="S0"> </span>left<span class="S0"> </span><span class="S10">=</span><span class="S0"> </span><span class="S10">(</span>Integer<span class="S10">)(</span>session<span class="S10">.</span>getAttribute<span class="S10">(</span><span class="S6">"left"</span><span class="S10">));</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span>out<span class="S10">.</span>println<span class="S10">(</span><span class="S6">"&lt;h1&gt;Continue guessing&lt;/h1&gt;&lt;p&gt;You have "</span><span class="S0"> </span><span class="S10">+</span><span class="S0"> </span>left<span class="S0"> </span><span class="S10">+</span><span class="S0"> </span><span class="S6">" chances left&lt;/p&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;form method=\"GET\" action=\"guess\"&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input type=\"TEXT\" name=\"guess\"&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input name=\"restart\" type=\"HIDDEN\" value=\"no\"/&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;input type=\"SUBMIT\" value=\"Guess\" /&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;/form&gt;&lt;br&gt;&lt;a href=\"guess?restart=yes\"&gt;Restart&lt;/a&gt;&lt;/body&gt;"</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">+</span><span class="S0"> </span><span class="S6">"&lt;/html&gt;"</span><span class="S10">);</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S0">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </span><span class="S10">}</span><br />
<span class="S10">}</span><br />
<span class="S0"></span></span>
</body>
</html>
